export default function initFormMeta(tabKey, moduleId, value) {
    if (tabKey === 'contract') {
        let template = this.props.meta.getMeta(), area = moduleId;
        if (template.formrelation && template.formrelation[moduleId]) {
            area = template.formrelation[moduleId][template.formrelation[moduleId].length - 1];
        }
        const hasIfprop = template[area].items.find(item => item.attrcode === 'ifprop');
        if (!hasIfprop) return;
        const promonth = template[area].items.find(item => item.attrcode === 'promonth');
        const prop_unit = template[area].items.find(item => item.attrcode === 'prop_unit');
        const probegindate = template[area].items.find(item => item.attrcode === 'probegindate');
        const probenddate = template[area].items.find(item => item.attrcode === 'probenddate');
        if (!value.value) {
            promonth.required = false;
            prop_unit.required = false;
            probegindate.required = false;
            probenddate.required = false;
            this.props.meta.setMeta(template);
            this.props.form.setFormItemsDisabled(moduleId, {
                'promonth': true,
                'prop_unit': true,
                'probegindate': true,
                'probenddate': true
            });
        } else {
            promonth.required = true;
            prop_unit.required = true;
            probegindate.required = true;
            probenddate.required = true;
            this.props.meta.setMeta(template);
            this.props.form.setFormItemsDisabled(moduleId, {
                'promonth': false,
                'prop_unit': false,
                'probegindate': false,
                'probenddate': false
            });
        }
    } else {
        let template = this.props.meta.getMeta(), area = moduleId;
        if (template.formrelation && template.formrelation[moduleId]) {
            area = template.formrelation[moduleId][template.formrelation[moduleId].length - 1];
        }
        const hasIfprop = template[area].items.find(item => item.attrcode === 'ifprop');
        if (!hasIfprop) return;
        const probmonth = template[area].items.find(item => item.attrcode === 'probmonth');
        const prop_unit = template[area].items.find(item => item.attrcode === 'prop_unit');
        const probegindate = template[area].items.find(item => item.attrcode === 'probegindate');
        const probenddate = template[area].items.find(item => item.attrcode === 'probenddate');
        if (!value.value) {
            probmonth.required = false;
            prop_unit.required = false;
            probegindate.required = false;
            probenddate.required = false;
            this.props.meta.setMeta(template);
            this.props.form.setFormItemsDisabled(moduleId, {
                'probmonth': true,
                'prop_unit': true,
                'probegindate': true,
                'probenddate': true
            });
        } else {
            probmonth.required = true;
            prop_unit.required = true;
            probegindate.required = true;
            probenddate.required = true;
            this.props.meta.setMeta(template);
            this.props.form.setFormItemsDisabled(moduleId, {
                'probmonth': false,
                'prop_unit': false,
                'probegindate': false,
                'probenddate': false
            });
        }
    }
}
